package cn.javadog.smartbreeding.record.config;

import java.time.LocalDateTime;

import org.apache.ibatis.reflection.MetaObject;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;

/**
 * @author 余勇
 */
public class MybatisObjectHandler implements MetaObjectHandler {

	private final static String FIELD_CREATE_TIME = "createTime";
	private final static String FIELD_UPDATE_TIME = "updateTime";

	@Override
	public void insertFill(MetaObject metaObject) {
		LocalDateTime localDateTime = LocalDateTime.now();
		this.setFieldValByName(FIELD_CREATE_TIME, localDateTime, metaObject);
		this.setFieldValByName(FIELD_UPDATE_TIME, localDateTime, metaObject);
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		this.setFieldValByName(FIELD_UPDATE_TIME, LocalDateTime.now(), metaObject);
	}
}